package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SortAnArrayList {

	public static void main(String[] args) {
		List<Employee> employeeList = new ArrayList<Employee>();
		Employee e1 = createEmployee(1L,"Shadab");
		Employee e2 = createEmployee(2L,"Gaur");
		employeeList.add(e2);
		employeeList.add(e1);
		for (Employee employee : employeeList) {
			System.out.println(employee.getName());
		}
		
		Collections.sort(employeeList);
		for (Employee employee : employeeList) {
			System.out.println(employee.getName());
		}
		
		//Comparator
		List<Student> studentList = new ArrayList<Student>();
		studentList.add(createStudent(3, "b"));
		studentList.add(createStudent(5, "c"));
		studentList.add(createStudent(1, "a"));
		for (Student student : studentList) {
			System.out.print(student.getName());
		}
		
		Collections.sort(studentList, new ComparatorStudent());
		System.out.print("\nSorted: ");
		for (Student student : studentList) {
			System.out.print(student.getName());
		}
	}

	private static Employee createEmployee(Long id, String name) {
		Employee e1 = new Employee();
		e1.setId(id);
		e1.setName(name);
		return e1;
	}
	
	private static Student createStudent(int id, String name) {
		Student e1 = new Student();
		e1.setId(id);
		e1.setName(name);
		return e1;
	}
}
